<?php
	namespace Common\Logic;
	use Common\Model\GallerysModel;
	class GallerysLogic extends GallerysModel{
		/*
		* Function:		getGallerysList
		* Description:	画廊列表
		* @param:		$page string 起始页
						$filter array 过滤数组
						$pageSize string 每页显示条数
		*/
		public function getGallerysList($page=1,$filter = '',$pageSize=20){
			$conditon = $this->getGallerysFilter($filter);
			return $this->where($conditon)->order('id desc')->limit(($page-1)*$pageSize,$pageSize)->select();
		}
		
		/*
		* Function:get:	getGallerysFilter
		* Description:	画廊列表搜索过滤项
		* @param:		$filter array 过滤数组
		*/
		public function getGallerysFilter($filter = ''){
			$conditon = array();
         $conditon['is_deleted'] = 0;
			if(empty($filter['flag'])){
				$conditon['status'] = 1;
			}
			if(!empty($filter['username'])){
				$conditon['username'] = $filter['username'];
			}
			if($filter['status']!=''){
				$conditon['status'] = $filter['status'];
			}
			if($filter['user_id']!=''){
				$conditon['user_id'] = $filter['user_id'];
			}
			return $conditon;
		}
		
		/*
		* Function:get:	getGallerysCount
		* Description:	画廊列表总数
		* @param:		$filter array 过滤数组
		*/
		public function getGallerysCount($filter = ''){
			$conditon = $this->getGallerysFilter($filter);
			return $this->where($conditon)->count();
		}
		
		/*
		* Function:		addGallerys
		* Description:	增加画廊
		* @param:		$data array 增加的数组
		*/
		public function addGallerys($data){
			return $this->add($data);
		}
		
		/*
		* Function:		getGallerysInfo
		* Description:	获取画廊信息 by row
		* @param:		$id int ID
		*/
		public function getGallerysInfo($id){
			return $this->where(array('id'=>$id))->find();
		}
		
		/*
		* Function:		updateGallerys
		* Description:	更新画廊
		* @param:		$data array 更新的数组
		*/
		public function updateGallerys($data){
			return $this->save($data);
		}
		
		/*
		* Function:		deleteGallerys
		* Description:	删除画廊
		* @param:		$id int ID
		*/
		public function deleteGallerys($id){
			return $this->where(array('id'=>$id))->delete();
		}
	}
?>